<?php

/**
 * This is the model class for table "{{user_meta}}".
 *
 * The followings are the available columns in table '{{user_meta}}':
 * @property string $user_id
 * @property string $meta_key
 * @property string $meta_value
 */
class UserMeta extends CActiveRecord
{
	public static function model($className=__CLASS__) {return parent::model($className);}
	public function tableName() {return '{{user_meta}}';}
	public function rules()
	{
		// Define only rules for those attributes that will receive user inputs.
		return array(
			array('user_id', 'required'),
			array('user_id', 'length', 'max'=>20),
			array('meta_key', 'length', 'max'=>255),
			array('meta_value', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_id, meta_key, meta_value', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
			'user'=>array(self::BELONGS_TO,'User','user_id'),
		);
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_id' 		=> Yii::t('usermeta', 'User'),
			'meta_key' 		=> Yii::t('usermeta', 'Meta Key'),
			'meta_value' 	=> Yii::t('usermeta', 'Meta Value'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id,false);
		$criteria->compare('meta_key',$this->meta_key,true);
		$criteria->compare('meta_value',$this->meta_value,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
			'sort'=>array('defaultOrder'=>'user_id DESC'),
			'pagination'=>array('pageSize'=>Yii::app()->session->get('adminPageSize',25)),
		));
	}
}